package com.destination.control;

import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.Menu;
import android.view.MotionEvent;
import android.widget.TabHost;

public class MainActivity extends ActivityGroup {
	private GestureDetector guestureDetetor=null;
	private TabHost tabHost=null;
	private static final int LARGE_MOVE=80;
	private int index=0;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		tabHost=(TabHost)findViewById(R.id.tabhost_main);
		tabHost.setup(this.getLocalActivityManager());
	
		tabHost.addTab(tabHost.newTabSpec("1").setIndicator("教室列表").setContent(new Intent(this,ShowClassRooms.class)));
		tabHost.addTab(tabHost.newTabSpec("2").setIndicator("课程列表").setContent(new Intent(this,ShowLessonSers.class)));
		tabHost.addTab(tabHost.newTabSpec("3").setIndicator("教室状态").setContent(new Intent(this,ShowClassState.class)));
	
	
		guestureDetetor=new GestureDetector(this,new SimpleOnGestureListener(){
			@Override
			public boolean onFling(MotionEvent e1, MotionEvent e2,
					float velocityX, float velocityY) {
				// TODO Auto-generated method stub
				if(e2.getX()-e1.getX()>LARGE_MOVE){
					
					tabHost.setCurrentTab(index = ( index == 2 )?  0 : ++index);   
					return true;
				}else if(e1.getX()-e2.getX()>LARGE_MOVE){
					
					tabHost.setCurrentTab(index = ( index == 0 )?  2 : --index); 
					return true;
				}
				return false;
			}
		});
		tabHost.setCurrentTab(0);
	} 

	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		return guestureDetetor.onTouchEvent(event);
	}
	

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	
}
